package com.itchen.controller;

import com.itchen.pojo.Book;
import com.itchen.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author げっしょく
 * @date 2021/9/16
 */
@RestController
@RequestMapping("/books")
public class BookController {

    @Autowired
    private BookService bookService;

    @PostMapping
    public Result save(@RequestBody Book book) {
        Result save = bookService.save(book);
        return save;
    }

    @PutMapping
    public Result update(@RequestBody Book book) {
        Result update = bookService.update(book);
        return update;
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        System.out.println(id);
        Result delete = bookService.delete(id);
        return delete;
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id) {
        System.out.println(id);
        Result byId = bookService.getById(id);
        return byId;
    }

    @GetMapping
    public Result getAll() {
        Result all = bookService.getAll();
        return all;
    }
}
